home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: cs.mun.ca!sjt
- From: sjt@cs.mun.ca (Stephen J. Tremblett)
- Subject: Re: Character String --> Integer
- Message-ID: <1996Feb20.185030.22691@cs.mun.ca>
- Sender: usenet@cs.mun.ca (NNTP server account)
- Organization: CS Dept., Memorial University of Newfoundland
- X-Newsreader: TIN [version 1.2 PL2]
- References: <4fb0ga$lsa@remus.rutgers.edu> <4ffr4e$4ji@madeline.INS.CWRU.Edu>
- Date: Tue, 20 Feb 1996 18:50:30 GMT
-
-
-
-
- I did this very recently in an assig.
- A char variable is just an int interpreted into the values of the ascii
- table. A char variable - 48 (ascii for 0) will result in the integer
- value of that digit.
-
-
- Steve T.
-
- Michael A. Balfour (mab22@po.CWRU.Edu) wrote:
-
- : In a previous article, wempa@remus.rutgers.edu (Force Of Nature) says:
-
- : >Is there an easy way to convert a character string such as '2425' to the
- : >integer 2425 ??? The only way I can think of is to pick off characters
- : >one at a time and use switch statements to determine the value (0-9) and
- : >then multiply by the correct power of 10. Is there an easier way to do
- : >this ???????
- : >
- : >
-
- : Just to throw a tiny spin on the discussion, if you don't know if the
- : character set for the string matches the native character set (i.e.
- : EBCDIC string on an ASCII machine), you can't use the standard library
- : functions. But rather than use a switch statement, you can LOGICAL AND
- : each character with 0x0F. It'll save you a little time anyways.
-
- : Mike Balfour
-
- : --
- : ----------------------------------+--------------------------------
- : Mike Balfour, Partner | BS/MS Candidate - ECMP
- : Overload Engineering | Case Western Reserve University
- : "New Ideas for a Brighter Future" | Cleveland, OH
- --
- I am far to young to feel so old
- And far too tired to care
- But I took down twenty bastards before they left me lying there
- - The Lowest of the Low
-